<!DOCTYPE html>

<html xmlns:th="http://www.w3.org/1999/xhtml">
<!--
    @Describe 代码生成器生成
    @Author   Professor_Kong
    @Date     2019-05-20
    @Email    logwto@163.com
-->
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/scroll-bar.css">
    <link rel="stylesheet" href="/static/css/sub-page.css">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_693759_wytlyqhtdtj1nhfr.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
        <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>会员管理</cite></a>
            <a><cite>权限管理</cite></a>
            <a><cite>权限维护</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--form表单-->
    <form class="layui-form" lay-filter="operateFormFilter" id="operateId">
              
                <div class="layui-form-item" hidden>
                    <label class="layui-form-label" style="width: 50px;padding: 9px 2px">ID</label>
                    <div class="layui-input-block" style="margin-left: 65px">
                        <input style="height: 32px" type="text"  id="id" name="id" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" >
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">菜单名称</label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <input style="height: 32px" type="text" id="authName" name="authName" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item" >
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">权限URL</label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <input style="height: 32px" type="text" id="menuUrl" name="menuUrl" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item" >
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">权限标志</label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <input style="height: 32px" type="text" id="auth" name="auth" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline" style="display: none">
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">是否折叠  0展开 1折叠   </label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <input style="height: 32px" type="text" id="checked" name="checked" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">权限类型</label>
                    <div class="layui-input-block" >
                        <input type="radio" lay-filter="radioFilter" name="isMenu" title="一级菜单" value=1>
                        <input type="radio" lay-filter="radioFilter" name="isMenu" title="二级菜单" value=2>
                        <input type="radio" lay-filter="radioFilter" name="isMenu" title="按钮" value=0>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">父级菜单</label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <select name="parentId" lay-filter="parentId" id="parentId">
                            <!--<option value=""></option>-->
                            <!--<option value="0">写作</option>-->
                            <!--<option value="1">阅读</option>-->
                        </select>
                    </div>
                </div>
                <div class="layui-form-item" >
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">icon</label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <input style="height: 32px" type="text" id="menuIcon" name="menuIcon" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" >
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">排序</label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <input style="height: 32px" type="text" id="orderNum" name="orderNum" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline" style="display: none">
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">创建时间</label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <input style="height: 32px" type="text" id="createTime" name="createTime" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline" style="display: none">
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">修改时间</label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <input style="height: 32px" type="text" id="updateTime" name="updateTime" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline" style="display: none">
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">创建人</label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <input style="height: 32px" type="text" id="createUser" name="createUser" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline" style="display: none">
                    <label class="layui-form-label" style="width: 80px;padding: 9px 2px">状态 0禁言  1启用</label>
                    <div class="layui-input-block" style="margin-left: 92px; margin-top: 4px; width: 76%">
                        <input style="height: 32px" type="text" id="status" name="status" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
        <div class="layui-form-item" style="text-align: right">
            <div class="layui-input-block" style="margin-right: 40px">
                <button class="layui-btn" style="height: 32px; line-height: 32px" lay-submit lay-filter="operateFilter" id="operateSubBtn">提交</button>
                <button type="reset" style="height: 32px; line-height: 32px" class="layui-btn">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script>
<script th:inline="none">


    //js 方式
    var formBackFillData = window.parent.document.getElementById("hidArea").value;

    layui.use(['element', 'form', 'jquery', 'laydate'], function () {
        var form = layui.form;
        var $ = layui.jquery;

        form.verify({
            birthdayVerify: [/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))(\s(([01]\d{1})|(2[0123])):([0-5]\d):([0-5]\d))?$/, '日期格式不正确']
        });

        form.on('radio(radioFilter)', function (data) {
            console.log(data.value);//判断单选框的选中值
            radioFill(data.value)
        });

        function radioFill(vals){
            if(vals==1){
                $('#parentId').empty(); //清空 下拉选项
                $("#parentId").attr("disabled",true);  //设置不可选择
                $('#parentId').append("<option value='1' selected>系统管理</option>")
                form.render();
            } else{
                $('#parentId').empty();                 //清空下拉选项
                $("#parentId").attr("disabled",false); //可选择
                $.ajax({
                    url:'/sys/permission/getPByLevel',
                    data:{level:vals},
                    type:'post',
                    dataType:'json',
                    success:function (res) {
                        $.each(res,function (key, val) {
                            $('#parentId').append("<option value='"+val.id+"' >"+val.authName+"</option>");
                        })
                        form.render();  //注意不可放到 if 或者 else 之外，否则不生效
                    }
                })
            }
        }

        form.on('submit(operateFilter)', function (data) {
            console.log(data.field);

            $.ajax({
                url:'/sys/permission/addOrUpdate',
                type:'post',
                dataType:'json',
                data:data.field,
                success: function (res) {
                    if(res.code== 1){
                        layer.alert("操作异常，请联系管理员！")
                    }else{
                        // 重载table  触发父页面查询
                        parent.layui.$("#reloadBtn").click();
                        // 刷新父页面
                        // window.parent.location.reload();

                        layer.msg("操作成功！", {icon: 6, time: 1000, anim: 4}, function () {
                            //关闭 表单弹窗
                            parent.layer.close(parent.layer.getFrameIndex(window.name));

                        });

                    }
                }
            })

            return false;
        });

        function init() {
            //清空表单
            $("#operateId")[0].reset();
            console.log(typeof(formBackFillData) != "undefined" && formBackFillData!= '')

            if(typeof(formBackFillData) != "undefined" && formBackFillData!=''){
                var pars1=JSON.parse(formBackFillData);
                console.log(pars1);

                form.val("operateFormFilter", pars1);
                var isM = pars1.isMenu;

                if(typeof(isM)!= 'undefined'){
                    console.log(isM)
                    $("input[name=isMenu][value='"+isM+"']").attr("checked",true);

                    radioFill(isM);
                    form.render();
                    if(isM!=1){
                        setTimeout(function() {

                            console.log(pars1.parentId)
                            console.log(  $("#parentId").val())
                            $("#parentId").val(pars1.parentId);
                            form.render('select');
                            },800
                        )
                    }

                }

                formBackFillData ='';
            }
        };

        init();
    })
</script>
</body>
</html>
